<template>
    <div v-if="modelValue" class="modal" @click="closeModal">
        <teleport to="body">
            <div class="modal-content">
                <h2>{{ content }}</h2>
                <button class="btn" @click="closeModal">关闭</button>
            </div>
        </teleport>
    </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
const content = ref("模态框内容");
const { modelValue } = defineProps({
    modelValue: Boolean,
});

const emits = defineEmits(["update:modelValue"]);

const closeModal = () => {
    emits("update:modelValue", false);
};
</script>

<style scoped>
.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 9999;
    padding: 20px;
    width: 240px;
    text-align: center;
    background-color: #fff;
    transform: translate(-50%, -50%);
}

.btn {
    padding: 4px 20px;
    margin-top: 10px;
    color: #fff;
    background-color: #cd5c5c;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
    width: 100%;
    height: 100%;
    background-color: #00000080;
}
</style>
